/**
 *
 * @author 
 *
 */
class Page5 extends egret.Sprite{
    private _main: Main;
    public constructor(main: Main) {
        super();
        this._main = main;

        
        //this.addEventListener(egret.TouchEvent.TOUCH_TAP,this.thisClick,this)
            
    }

    private touchMove(e: egret.TouchEvent): void {
        this.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.thisClickMove,this);
    }
    
    private mClickNum: number = 0;
    private mSkin: Boolean;
    private m_move_y = 0;
    private mChangeing: boolean;

    private thisClickMove(e: egret.TouchEvent): void {
        if(this.mChangeing) return;
        if(this.m_move_y == 0)
            this.m_move_y = e.stageY;
        else
            if(this.m_move_y > e.stageY)
            {
                this.mChangeing = true;
                egret.setTimeout(clean, this, 500);
                this._main.toPage6(this, true);
            }
            else if(this.m_move_y == e.stageY)
                ;
            else
            {
                this.mChangeing = true;
                egret.setTimeout(clean, this, 500);
                this._main.toPage4(this, false);     
            }
            
        function clean(): void
        {
            this.mChangeing = false;
        }
    }
    
    private thisClick(e: egret.TouchEvent): void
    {
        if(e.target.parent == this.btn1 || e.target.parent == this.btn2 || e.target.parent == this.btn3) return;

        this.mClickNum++;
        if(this.mClickNum == 1)
        {
            this.mSkin = true;
            return;
        }

        if(this.mClickNum >= 2)
        {
            this._main.toPage6(this, true);
            return;
        }
    }
    

    public start(): void {
        egret.setTimeout(this.touchMove,this,this.mSkin ? 0 : 500);
        
        var bg: eui.Image = new eui.Image;
        bg.source = "1_1_png";
        this.addChild(bg);
        
        var bg2: eui.Image = new eui.Image;
        bg2.source = "n_arrows_png";
        bg2.x = 300;
        bg2.y = 960;
        this.addChild(bg2);
        
        egret.setTimeout(this.page1, this, this.mSkin ? 0 :100);
    }
    
    public page1(): void {
        var bg: eui.Image = new eui.Image;
        bg.source = "n_5_1_png";
        bg.x = -100;
        bg.y = 50;
        bg.alpha = 0;
        this.addChild(bg);

        egret.Tween.get(bg).to({
            x: 60,alpha:1,ease: egret.Ease.bounceInOut
        }, this.mSkin ? 0 :500)
        
        var bg: eui.Image = new eui.Image;
        bg.source = "n_5_2_png";
        bg.x = -100;
        bg.y = 250;
        bg.alpha = 0;
        this.addChild(bg);

        egret.Tween.get(bg).to({
            x: 0,alpha:1,ease: egret.Ease.bounceInOut
        },this.mSkin ? 0 : 500)
        
        var bg: eui.Image = new eui.Image;
        bg.source = "n_5_3_png";
        bg.x = 80;
        bg.y = 1000;
        bg.alpha = 0;
        this.addChild(bg);

        egret.Tween.get(bg).to({
            y: 450,alpha:1,ease: egret.Ease.bounceInOut
        },this.mSkin ? 0 : 500)
        
        this.bg = bg;
        
        this.btn1 = new Button1;
        this.btn1.addEventListener(egret.TouchEvent.TOUCH_TAP,this.btn1Click,this);
        this.btn1.x = 480;
        this.btn1.y = 270;
        this.addChild(this.btn1);

        this.btn2 = new Button1;
        this.btn2.x = 480;
        this.btn2.y = 360;
        this.addChild(this.btn2);
        this.btn2.addEventListener(egret.TouchEvent.TOUCH_TAP,this.btn2Click,this);

        this.btn3 = new Button1;
        this.btn3.x = 480;
        this.btn3.y = 450;
        this.addChild(this.btn3);
        this.btn3.addEventListener(egret.TouchEvent.TOUCH_TAP,this.btn3Click,this);

        var bg: eui.Image = new eui.Image;
        bg.source = "n_4_10_png";
        bg.x = 540;
        bg.y = 300;
        bg.touchEnabled = false;
        //        bg.alpha = 0;
        this.addChild(bg);

        this.select(this.btn1);

        this.mClickNum = 1;
    }
    
    private bg:eui.Image ;
    

    
    private btn1:Button1;
    private btn2:Button1;
    private btn3:Button1;
    
    private btn1Click(e:egret.TouchEvent):void
    {
        this.bg.source = "n_5_3_png";
        this.select(e.currentTarget);
        egret.log("输出1");
    }
    
     private btn2Click(e:egret.TouchEvent):void
    {
         this.select(e.currentTarget);
         this.bg.source = "n_5_31_png";
        egret.log("输出2");
    }
    
     private btn3Click(e: egret.TouchEvent): void
     {
         this.select(e.currentTarget);
         this.bg.source = "n_5_311_png";
         egret.log("输出3");
     }
     
     private select(btn:Button1):void
     {
         this.btn1.select(false);
         this.btn2.select(false);
         this.btn3.select(false);
         
         btn.select(true);
     }
}
